package max.ta.data.plot;

import java.util.Date;

import max.ta.data.plot.data.MathLine;
import max.ta.data.plot.data.MathPoint;
import max.ta.data.plot.data.MathSurface;

import org.jfree.data.time.Day;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;

public class TimerSeriesConverter {

    public static TimeSeriesCollection createDataset(MathSurface<Date, Double> points) {
	final TimeSeriesCollection dataset = new TimeSeriesCollection();
	for (MathLine<Date, Double> pointSet : points.getElements()) {
	    TimeSeries s = createDataSerie(pointSet);
	    dataset.addSeries(s);
	}
	return dataset;
    }

    private static TimeSeries createDataSerie(MathLine<Date, Double> pointSet) {
	final TimeSeries s1 = new TimeSeries(pointSet.getName());
	for (MathPoint<Date, Double> p : pointSet.getElements()) {
	    s1.add(new Day(p.getX()), p.getY());
	}
	return s1;
    }
}
